package proxy;

import lombok.extern.slf4j.Slf4j;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @author zenghy
 **/
@Slf4j
public class SubjectHandler implements InvocationHandler {

    private Subject subject;

    public SubjectHandler(Subject subject) {
        this.subject = subject;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        try {
            log.info("do before subject do");
            return method.invoke(subject, args);
        } catch (Exception e) {
            log.error("do when exception");
            throw e;
        } finally {
            log.info("do after subject do");
        }
    }
}
